#!/bin/bash

prog="zabbix-libvirt.stats"
#plese also modify ver in zabbix-libvirt.stats.spec
ver="0.0.2"

mkdir ${prog}-${ver}
cp -a \
 libvirt_domstats.conf \
 libvirt_domstats.py \
 README \
 ${prog}-${ver}/
tar zcf ${prog}-${ver}.tar.gz ${prog}-${ver}
rm -rf ${prog}-${ver}

specfile="${prog}.spec"

if [ $# -eq 0 ];then
  echo "Usage: $0 -ba|-bp"
  exit
fi
HOME=/tmp/`whoami`
builddir=${HOME}/rpmbuild

mkdir -p ${builddir}/SOURCES ${builddir}/SPECS
cp ${prog}-${ver}.tar.gz *.patch ${builddir}/SOURCES/
rm ${prog}-${ver}.tar.gz 

cp ${specfile} ${builddir}/SPECS/
cd ${builddir}/SPECS && rpmbuild ${1} ${specfile}
